package leecode;

import java.util.HashSet;
import java.util.Set;

//第4天
public class leetcode5 {
    //第一题
    public int findRepeatNumber(int[] nums) {
        Set<Integer>set=new HashSet<>();
        for (int i = 0; i < nums.length; i++) {
            if(!set.contains(nums[i])) {
                set.add(nums[i]);
            }else {
                return nums[i];
            }
        }
        return 0;
    }
    //第二题
    public int search(int[] nums, int target) {
        int count=0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]==target){
                count++;
            }
        }
        return count;
    }
    //第三题
    public int missingNumber(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
                if(i!=nums[i]){
                    return i;
                }
        }
        return 0;
    }
}
